import { defineStore } from "pinia";
import type { StoreDefinition } from "pinia";

type BoundingClientType = {
	width: number;
	height: number;
	top: number;
	right: number;
	bottom: number;
	left: number;
};

type SystemStoreState = {
	language: "zhCn" | "en";
	bounding: BoundingClientType;
	navBarHeight: number;
	statusBarHeight: number;
};

export const useStoreSystem: StoreDefinition<string, SystemStoreState> = defineStore<string, SystemStoreState>(
	"system",
	{
		state: (): SystemStoreState => ({
			language: "zhCn",
			bounding: uni.getMenuButtonBoundingClientRect(),
			navBarHeight: 0,
			statusBarHeight: 0
		}),

		actions: {
			/**
			 * @description 更新语言
			 * */
			updateLanguage(value: "zhCn" | "en") {
				this.language = value;
			},

			/**
			 * @description 导航栏高度
			 * */
			updateNavBarHeight(value: number) {
				this.navBarHeight = value;
			},

			/**
			 * @description 导航栏高度
			 * */
			updateStatusBarHeight(value: number) {
				this.statusBarHeight = value;
			}
		},

		getters: {
			getNavBarHeight(state) {
				return state.navBarHeight + state.statusBarHeight;
			},
			navBarHeightStyle(state) {
				return {
					width: "100%",
					paddingTop: state.statusBarHeight + "px",
					height: state.navBarHeight + "px"
				};
			}
		}
	}
);
